<?php
class Bootstrap_DbAdapter extends Bootstrap_Abstarct{		
	const CACHE_CLASS_DBADAPTER_NAME = 'class_dbAdapter';	
	
	static public function build()	{	
		$config = Zend_Registry::get('config');				
		if(Zend_Registry::isRegistered('dbAdapter')){
			$dbAdapter = Zend_Registry::get('dbAdapter');
		}else{			
			$dbAdapter = self::loadCache(self::CACHE_CLASS_DBADAPTER_NAME);
			if (!$dbAdapter instanceof Zend_Db_Adapter_Abstract) {				
				$dbAdapter = Zend_Db::factory($config->db->adapter, $config->db->config->toArray());
				$dbAdapter->getProfiler()->setEnabled(Config_Xml::isTrue($config->db->profiler));
				self::saveCache($dbAdapter, self::CACHE_CLASS_DBADAPTER_NAME);
			}			
		}	
		if (!$dbAdapter instanceof Zend_Db_Adapter_Abstract) {
			throw new Exception('DbAdapter is null.PLease check the db Adapter.');
		}
		$dbAdapter->query('set names ' . $config->db->config->charset);
		Zend_Db_Table::setDefaultAdapter ( $dbAdapter );	
		Zend_Registry::set('dbAdapter',$dbAdapter);		
		return $dbAdapter;
	}
}